/*******************************************************************************
 * Copyright 2011-2012 Dik Grapendaal
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package sh.grapendaal.tsuushin.module.commands;

import sh.grapendaal.tsuushin.annotation.Command;
import sh.grapendaal.tsuushin.annotation.Module;
import sh.grapendaal.tsuushin.annotation.Permission;
import sh.grapendaal.tsuushin.core.Context;
import sh.grapendaal.tsuushin.message.NickMessage;
import sh.grapendaal.tsuushin.message.PrivateMessage;
import sh.grapendaal.tsuushin.message.QuitMessage;
import sh.grapendaal.tsuushin.service.PermissionService;

@Module(author = "Dik Grapendaal", version = "0.0.1")
@Permission(names = { "commands_moderator" })
public class Commands {
	
	@Command(trigger = "whereami")
	public void onWhereAmI(Context context, PrivateMessage message) {
		PrivateMessage outgoing = new PrivateMessage();
		outgoing.setDestination(message.getDestination());
		outgoing.setContent("You're in " + message.getDestination() + "!");
		context.getBot().send(outgoing);
	}
	
	@Command(trigger = "setnickname", permission = PermissionService.PERMISSION_BOT_OWNER)
	public void onSetNickname(Context context, PrivateMessage message) {
		String[] chunks = message.getContent().split(" ");
		if (chunks.length > 1) {
			NickMessage nickname = new NickMessage();
			nickname.setNickname(chunks[1]);
			context.getBot().send(nickname);
		} else {
			PrivateMessage outgoing = new PrivateMessage();
			outgoing.setDestination(message.getDestination());
			outgoing.setContent("Usage: !setnickname NewNickname");
			context.getBot().send(outgoing);
		}
	}
	
	@Command(trigger = "lequit", permission = PermissionService.PERMISSION_BOT_OWNER)
	public void onLeQuit(Context context, PrivateMessage message) {
		QuitMessage outgoing = new QuitMessage();
		outgoing.setContent("kbie");
		context.getBot().send(outgoing);
	}
	
}
